package com.example.takeaway.api;

import com.example.takeaway.common.R;
import com.example.takeaway.model.vo.UserTokenVO;
import com.example.takeaway.service.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 邢晨旭
 * {@code @date} 2023/10/14
 */
@RestController
@RequestMapping("/admin")
public class AdminLoginApi {

    @Resource
    UserService userService;

    @GetMapping("/login/code")
    public R<Void> sendCode(@RequestParam String email) {
        userService.sendAdminCode(email);
        return R.ok();
    }

    @PostMapping("/login/code")
    public R<UserTokenVO> loginByCode(@RequestParam String email, @RequestParam String code) {
        return R.ok(userService.adminLoginByCode(email, code));
    }

}
